<?php
if( (!isset($_SESSION['next'])) || ($_SESSION['next'] < 4) )
{
	echo '<script laguage="javascript"> 
              window.location.href = "../installation/";
          </script>';
}
//status = 0: khong co loi, 1: co loi
$status = 0;
$message = '';
$scriptDir     = SITE_PATH.'/library/api/shell';
$nimbusClient = '/home/bkloud/BkloudClient/';
$userDir = '/home/bkloud/BkloudUser';
$nimbusServer   = '/home/bkloud/Nimbus/';
$templateDir   = '/home/bkloud/BkloudTemplate/';
$userHome   = '/home/bkloud';

if(isset($_POST['scriptDir']))
{
	$scriptDir     = trim($_POST['scriptDir']);
	$nimbusClient = trim($_POST['nimbusClient']);
	$userDir = trim($_POST['userDir']);
	$nimbusServer   = trim($_POST['nimbusServer']);
	$templateDir = trim($_POST['templateDir']);
	$userHome   = trim($_POST['userHome']);
	
	if(($scriptDir == '') || ($nimbusClient == '') || ($userDir == '') || ($nimbusServer == '') || ($templateDir == '') || ($userHome == ''))
	{
		$status = 1;
		$message = "Nhập thiếu thông tin";
	}
	
	if($status == 0)
	{
		$content = '';
		$content .= "ScriptDir=".$scriptDir."\n";
		$content .= "NimbusClient=".$nimbusClient."\n";
		$content .= "UserDir=".$userDir."\n";
		$content .= "NimbusServer=".$nimbusServer."\n";
		$content .= "TemplateDir=".$templateDir."\n";
		$content .= "UserHome=".$userHome;
		
 		$fileOption = SITE_PATH.'/library/api/shell/options.list';
 		file_put_contents($fileOption,$content);
 		
 		$_SESSION['next'] = 5;
			echo '<script laguage="javascript"> 
             		 window.location.href = "../installation/?frame=finish";
          		  </script>';
	}
}
?>

       <script>
        	addActive('config');
        	
        </script>
    	<div id="topright">
        	<div id="topright1">
        		<span> Cấu hình Nimbus </span> 
            </div>
            <div id="topright2">
            	<button id="next" onclick="document.forms['config'].submit()">
                </button>
            </div> 
    	</div> 
        
    	<div id="botright">
			<div id="botright1">
				  <form id="config" action="../installation/?frame=configuration" method="post">
     				 <?php
        				if($status == 1)
        				{
      				?>      
      				<div style="padding-bottom:15px; color:#FF0000;width:400px;font-weight:bold;">
      				<img src="images/error.png" width="32" height="32" style="float:left; margin-right:10px;"/>
      				Lỗi : <?php echo $message;?>
      				</div>
      				<?php
       				}
      				?>
			      	<p  style="padding: 10px; margin: 0px;">
			        	<label style="width:220px;float:left;font-weight: bold;padding-top: 5px;">Thư mục chứa shell</label>
			        	<input type="text" name="scriptDir" style="padding: 5px;width: 300px;" value="<?php echo $scriptDir;?>"/>
			       </p>
			       <p  style="padding: 10px; margin: 0px;">
			        	<label style="width:220px;float:left;font-weight: bold;padding-top: 5px;">Đường dẫn NimbusClient (*)</label>
			        	<input type="text" name="nimbusClient" style="padding: 5px;width: 300px;" value="<?php echo $nimbusClient;?>"/>
			       </p>
			       <p  style="padding: 10px; margin: 0px;">
			        	<label style="width:220px;float:left;font-weight: bold;padding-top: 5px;">Đường dẫn NimbusUser</label>
			        	<input type="text" name="userDir" style="padding: 5px;width: 300px;" value="<?php echo $userDir;?>"/>
			       </p>
			       <p  style="padding: 10px; margin: 0px;">
			        	<label style="width:220px;float:left;font-weight: bold;padding-top: 5px;">Đường dẫn NimbusServer (*)</label>
			        	<input type="text" name="nimbusServer" style="padding: 5px;width: 300px;" value="<?php echo $nimbusServer;?>"/>
			       </p>
			        <p  style="padding: 10px; margin: 0px;">
			        	<label style="width:220px;float:left;font-weight: bold;padding-top: 5px;">Đường dẫn Template (*)</label>
			        	<input type="text" name="templateDir" style="padding: 5px;width: 300px;" value="<?php echo $templateDir;?>"/>
			       </p>
			       <p  style="padding: 10px; margin: 0px;">
			        	<label style="width:220px;float:left;font-weight: bold;padding-top: 5px;">Đường dẫn Home</label>
			        	<input type="text" name="userHome" style="padding: 5px;width: 300px;" value="<?php echo $userHome;?>"/>
			       </p>
			     </form> 
			</div>       
			<div id="botright2">
			  <p>Cấu hình các thông số của nimbus</p>
			  <p>Các trường thông tin đều là bắt buộc</p>
			  <p>(*) Bắt buộc có ký tự / ở cuối.</p>
			</div>
    	</div>